part of '../repository.dart';

const _kMoneyAmountValueKey = 'value';
const _kMoneyAmountCurrencyKey = 'currency';

class _MoneyAmountDto extends Equatable {
  const _MoneyAmountDto._internal({
    required this.value,
    required this.currency,
  });

  final String value;
  final String currency;

  @override
  List<Object?> get props {
    return [
      value,
      currency,
    ];
  }

  factory _MoneyAmountDto.fromJson(Map<String, dynamic> json) {
    return _MoneyAmountDto._internal(
      value: json[_kMoneyAmountValueKey],
      currency: json[_kMoneyAmountCurrencyKey],
    );
  }

  factory _MoneyAmountDto.fromEntity(WebMoneyAmount moneyAmount) {
    return _MoneyAmountDto._internal(
      value: moneyAmount.value,
      currency: moneyAmount.currency,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kMoneyAmountValueKey: value,
      _kMoneyAmountCurrencyKey: currency,
    };
  }

  WebMoneyAmount toEntity() {
    return WebMoneyAmount(
      value: value,
      currency: currency,
    );
  }
}
